package vip.mall.common.result;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import vip.mall.common.enums.CommonResponseCode;

/**
 * @author ASUS
 * @Date 2025/2/10 9:20
 * @Descripition 通用返回结果
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
@Schema(description = "通用结果")
public class CommonResult {
    @Schema(description = "状态码")
    private int code;
    @Schema(description = "提示信息")
    private String message;
    @Schema(description = "数据")
    private Object data;
    /*
    * 成功返回结果
     */
    public static CommonResult success(Object data) {
        return new CommonResult(CommonResponseCode.SUCCESS.getCode(), "操作成功", data);
    }
    /*
    * 成功返回结果
     */
    public static CommonResult success() {
        return new CommonResult(CommonResponseCode.SUCCESS.getCode(), "操作成功", null);
    }
    /*
    * 失败返回结果
     */
    public static CommonResult error(String message) {
        return new CommonResult(CommonResponseCode.ERROR.getCode(), message, null);
    }
    /*
     * 失败返回结果
     */
    public static CommonResult error(Integer code,String message) {
        return new CommonResult(code, message, null);
    }
    /*
    * 失败返回结果
     */
    public static CommonResult error() {
        return new CommonResult(500, "操作失败", null);
    }

    /**
     *  失败返回结果
     */
    public static CommonResult error(CommonResponseCode commonResponseCode) {
        return new CommonResult(commonResponseCode.getCode(), commonResponseCode.getMessage(), null);
    }
    /**
     *  失败返回结果
     */
    public static CommonResult error(CommonResponseCode commonResponseCode, String message) {
        return new CommonResult(commonResponseCode.getCode(),message, null);
    }
}
